package com.dubious.interview.euler;

import org.joda.time.DateTime;

public class Problem6 {

    /**
     * The sum of the squares of the first ten natural numbers is,
     * 
     * 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is,
     * 
     * (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the
     * first ten natural numbers and the square of the sum is 3025 385 = 2640.
     * 
     * Find the difference between the sum of the squares of the first one hundred natural numbers
     * and the square of the sum.
     */
    public static void main(String[] args) {
        System.out.println("Start Time: " + new DateTime());

        System.out.println("Difference for first 100 natural numbers: " + difference(100));

        System.out.println("End Time: " + new DateTime());
    }

    /**
     * Find the difference between the square of the sum and the sum of the squares for the first n
     * natural numbers.
     * 
     * @param n
     * @return
     */
    public static long difference(int n) {
        long sumOfSquares = 0;
        for (int i = 1; i <= n; i++) {
            sumOfSquares += i * i;
        }

        System.out.println("sum of squares: " + sumOfSquares);

        long squareOfSum = 0;
        for (int i = 1; i <= n; i++) {
            squareOfSum += i;
        }

        squareOfSum = squareOfSum * squareOfSum;

        System.out.println("square of sum : " + squareOfSum);

        return squareOfSum - sumOfSquares;
    }
}
